package com.hyd.tweet.twitter.command;

import com.hyd.tweet.twitter.StatusFormatter;
import twitter4j.Paging;
import twitter4j.Status;
import twitter4j.TwitterException;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * (description)
 *
 * @author yiding.he
 */
public class AtMeCommand extends Command {

    @Override
    public List<String> processCommand() throws TwitterException {

        int mentionsCount = 20;
        if (arguments.size() > 0) {
            mentionsCount = Math.min(Integer.parseInt(arguments.get(0)), 20);
        }

        List<Status> statuses = twitter.getMentions(new Paging(1, mentionsCount));
        Collections.reverse(statuses);

        List<String> result = new ArrayList<String>();
        for (Status status : statuses) {
            int rollerId = user.pushToRoller(status);
            result.add(StatusFormatter.formatStatus(twitterUser, status, rollerId));
        }

        result.add("——已列出最近提到我的" + statuses.size() + "条推。");

        return result;
    }
}
